<?php
class Admin extends CI_Controller{

	function select(){
		$page = $_GET["page"];
		$limit = $_GET["limit"];
		$this->load->model('server/news_model');
		$cont = [
			'table' => 'admin',
			'where'=>[
				'username !='=>'admin'
			],
			'limit' => [($page - 1) * $limit, $limit]
		];
		$data = $this->news_model->select_form($cont);
		echo json_encode($data, JSON_UNESCAPED_UNICODE) . PHP_EOL;
	}

	//删除id号
	function delete(){
		$id = $_GET["id"];
		$this->load->model('server/news_model');
		$cont = [
			'table' => 'admin',
			'where'=>[
				'id'=>$id
			]
		];
		$data = $this->news_model->delete($cont);
		echo json_encode($data, JSON_UNESCAPED_UNICODE) . PHP_EOL;
	}

	function add(){
		$username = $_GET["username"];
		$password = $_GET["password"];

		$this->load->model('server/news_model');

		$cont = [
			'table' => 'admin',
			'data'=>[
				'username'=>$username,
				'password'=>hash("sha256",$password)
			]
		];
		$data = $this->news_model->insert_one($cont);
		echo json_encode($data, JSON_UNESCAPED_UNICODE) . PHP_EOL;
	}
}
